package sample;
import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) {
        Socket socket = null;
        try {
            socket = new Socket("localhost", 8800);
            OutputStream os = socket.getOutputStream();
            InputStream is=socket.getInputStream();
            ObjectOutputStream oss = new ObjectOutputStream(os);
            Scanner input = new Scanner(System.in);
            System.out.println("请输入您的账号：");
            String username = input.next();
            System.out.println("请输入您的密码：");
            String password = input.next();
            User user = new User(username, password);
            oss.writeObject(user);
            socket.shutdownOutput();
            //读出服务器的信息
            String reply=null;
            BufferedReader bis=new BufferedReader(new InputStreamReader(is));
            while((reply=bis.readLine())!=null){
                System.out.println("我是客户端，服务器相应为："+reply);
            }
            //关闭流
            bis.close();
            oss.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
        }
    }
}